package org.example.Server.controller.survey;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.survey.SemSurvey;
import org.example.Server.model.survey.SurveyPaperDTO;
import org.example.Server.model.survey.SurveySemDTO;
import org.example.Server.service.sruvey.SurveySemService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教师创建调查问卷
 */
@RestController
@Slf4j
@RequestMapping("/youxich/survey/sem")
public class SemSurveyController {
    @Autowired
    private SurveySemService surveySemService;

    /**
     * 课堂添加新问卷
     *
     * @param surveyPaperDTO
     * @return
     */
    @PostMapping()
    public ResultAPI saveSurveySem(@RequestBody SurveyPaperDTO surveyPaperDTO) {
        return surveySemService.saveSurvey(surveyPaperDTO);
    }


    /**
     * 课堂问卷的规则设置
     *
     * @param surveySemDTO
     * @return
     */
    @PostMapping("setting")
    public ResultAPI setting(@RequestBody SurveySemDTO surveySemDTO) {
        SemSurvey survey = new SemSurvey();
        BeanUtils.copyProperties(surveySemDTO, survey);
        surveySemService.updateById(survey);
        return ResultAPI.success();
    }

    /**
     * 获取课堂未发布、未开始、已开始、已结束列表
     *
     * @param semId
     * @return
     */
    @GetMapping
    public ResultAPI getSurveySemList(@RequestParam Integer semId, @RequestParam(required = false) Integer status) {
        return surveySemService.getSemSurveyList(semId, status);
    }

    @DeleteMapping("{ids}")
    public ResultAPI deleteSurvey(@PathVariable List<Integer> ids) {
        return surveySemService.deleteSurvey(ids);
    }

    /**
     * 获取问卷试题列表以及答卷人数
     *
     * @param sem_id
     * @param survey_id
     * @param paper_id
     * @return
     */
    @GetMapping("list")
    public ResultAPI getSurveyQsList(@RequestParam Integer sem_id,
                                     @RequestParam Integer survey_id,
                                     @RequestParam(required = false) Integer paper_id) {
        return surveySemService.getSurveyQsList(sem_id, survey_id, paper_id);
    }


}
